
 begintownscript;

 variables;

 int i,j,k,r1,choice;

 body;

 beginstate INIT_STATE;
	set_level(41,25);

	if (get_flag(6,11) == 0) {
		force_instant_terrain_redraw();
		message_dialog("You enter the ruined city. You noticed something was moving within the city when you were approaching it. Now you can tell what they were, undead. Possibly raised from the dead of the city, or then summoned from another plane.","They have taken the city. You can hear them, see them, even smell them wandering the city aimlessly. Whoever did this to the city, wanted to make sure it stayed that way.");
		set_flag(6,11,1);
}
	if (get_flag(6,12) == 1)
		erase_char(6);

	if (get_flag(6,13) > 0)
		erase_char(7);

break;

 beginstate START_STATE;

 if (get_flag(6,8) == 1) {
	message_dialog("The spellcasting spirit, whoever it was, has been put to rest. It seemed that it was in charge of the undead, but you are positive it did not create them.","");
	set_flag(6,8,2);
}

break;

 beginstate EXIT_STATE;

break;

 beginstate 10;
	if (get_flag(6,1) == 0) {
		message_dialog("The temple you entered is considerably large. You look around it and notice one thing. Apart from the collapsed walls, the temple is untouched. Something in this temple is repelling the undead.","");
		set_flag(6,1,1);
}
break;

 beginstate 11;
	if (get_flag(6,2) == 0) {
		message_dialog("As soon as you enter the room, an empty flask rolls at your feet. At first you think a zombie or a skeleton kicked it, but then you hear a voice shouting. _So ye finally realized how to work the door, ye undead scumbags!_.","You look inside and see a soldier sitting in a corner.");
		set_flag(6,2,1);
}
break;

 beginstate 12;
	if (get_flag(6,3) == 0) {
		message_dialog("The foundry is surprisingly intact compared to the other buildings. You see bars of irons and iron weaponry all around you, but no signs of fighting.","You also hear mad shrieking laughter coming from the back of the foundry, and low heavy breathing.");
		activate_hidden_group(1);
		set_flag(6,3,1);
}
break;

 beginstate 13;
	if (get_flag(6,4) == 0) {
		message_dialog("You come to the remains of a building. It was once made of stone, from reasonably fine stone based on the rubble, now it is but a huge pile of rock.","Most likely if you started to dig, you'd find the remains of the poor people who were inside this building.");
		set_flag(6,4,1);
}
break;

 beginstate 14;
	if (get_flag(6,5) == 0) {
		message_dialog("In this concealed room, you find the body of a woman wearing robes of a priest. Judging from the blood stains, she dragged herself here. Possibly she was trying to hide.","Or then she dragged herself here for some other reason. You may never know.");
		set_flag(6,5,1);
}
break;

 beginstate 15;
	if (get_flag(6,6) == 0) {
		message_dialog("You are positive that the attack came from the north. The walls are in much worse shape there. Only strong magic could be this devastating. You can't even begin to figure out who did this.","");
		set_flag(6,6,1);
}
break;

 beginstate 16;
	reset_dialog();
	add_dialog_str(0,"There is a closed book on the pedestal. It has no title, but there is a bloody palm print on the cover. This book may well be the last thing the priest touched.",0);
	add_dialog_choice(0,"Read the book.");
	add_dialog_choice(1,"Leave.");
	choice = run_dialog(1);

	if (choice == 1) {
		reset_dialog();
		add_dialog_str(0,"You open the book. To your disappointment, it contains no magical rituals. It is a diary of Sister Naela, the head of this church. The first pages tell her story. She was once a priest of a religion called the _Anama_ from the Isle of Bigail.",0);
		add_dialog_str(1,"Reading on you find out she had some disagreements, with the head of the church, about the fundamental beliefs of their faith, whose key belief is that the evil doings of magic outweighs the good and therefore, magic should not be used.",0);
		add_dialog_str(2,"The book does not reveal what disagreements she had but it reveals one thing. She was exiled. The following pages tell how she wandered Empire lands and eventually wound up in Faerengrove.",0);
		add_dialog_str(3,"The rest seems to be just daily notes about the temple and its attendance, which had been quite good. You flip to the last page to see the priests final entry. It has been written by shaking hands and consists of a single word: demons.",0);
		run_dialog(1);
}
break;

 beginstate 17;
	if (get_flag(6,10) == 0 && has_special_item(1)) {
		message_dialog("Well, this is the captain's office. You take one of the letters captain Yarling gave you, out of your pocket. She won't be getting any help here, and you can't deliver this letter.","");
		set_flag(6,10,1);
}
break;
	

 beginstate 20;
	if (get_flag(6,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"You approach the altar of the temple. Like the rest of the temple, it too has been left untouched by the undead. The aura it emits must be powerful indeed to keep the undead away.",0);
		add_dialog_str(1,"There is room for one person to kneel in front of the altar. If you wish, a member of your party can pray.",0); 
		add_dialog_choice(0,"Pray.");
		add_dialog_choice(1,"Leave.");
		choice = run_dialog(1);

	if (choice == 1)
		set_state_continue(21);
}
break;

 beginstate 21;
	choice = run_select_a_pc(0);
	if (choice == 0)
		set_state_continue(20);
	set_state_continue(22);
break;

 beginstate 22;
		j = get_selected_pc();
		if (get_stat_levels_bought(j,12) > 0 && get_stat_levels_bought(j,11) == 0) {
			message_dialog("You kneel at the altar. At first nothing happens, then the altar begins to glow. A surge of energy springs from the altar and hits your praying companion.","It burns slightly, but when it stops, you feel more powerful.");
			change_spell_level(j,1,5,1);
			damage_char(j,15,3);
			set_flag(6,0,1);
}
		if (get_stat_levels_bought(j,11) > 0) {
			message_dialog("You kneel at the altar. At first nothing happens, then a surge of energy shoots rapidly from the altar. It hits your praying companion and throws him back several feet.","The event only lasted seconds, but it left you drained and burned.");
			damage_char(j,40,1);
			change_char_energy(j,-50);
			relocate_character(j,23,45);
}
		if (get_stat_levels_bought(j,12) == 0 && get_stat_levels_bought(j,11) == 0)
			message_dialog("You kneel at the altar and place a prayer to whatever it has been dedicated to. After a moment of silent praying, you get up.","Apart from a felling of tranquillity, nothing happened.");

break;

 beginstate 23;
	if ((char_ok(6) == FALSE) && (get_flag(2,4) < 2) && (get_flag(6,13) == 0)) {
		message_dialog("A violent gush of air opens the door. A shrieking ghost of a woman comes screaming towards you. _YoU KilLeD MY bRotheR! WHY?!_","There is no room for conversation.");
		activate_hidden_group(5);
		erase_char(7);
		set_terrain(52,53,53);
		set_flag(6,13,1);
}
 break;